import {
	RouterMount,
	createRouter
} from 'uni-simple-router';
import routes from './routes.js'
import {
	passRoutes
} from '../common/config/config.js'

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routes: routes
});

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	const user = uni.getStorageSync("user") || {}
	if (!user.token) { // 未登录
		const res = passRoutes.some(name => name === to.name)
		if (!res && to.name !== "login") {
			router.push({
				name: "login"
			})
		}
	}
	next()

});

// 全局路由后置守卫
router.afterEach((to, from) => {
	
})

export {
	router,
	RouterMount
}
